feat(apps): set @datadog/apps backend context#457
Draft
Scott-Meyer wants to merge 4 commits into
Draft
Conversation
Scott-Meyer
force-pushed
the
scott.meyer/datadog-apps-backend-runtime-entry
branch
2 times, most recently
from
July 17, 2026 01:18
86682ae to
145ec69
Compare
Scott-Meyer
force-pushed
the
scott.meyer/datadog-apps-backend-runtime-entry
branch
from
July 17, 2026 23:44
145ec69 to
d982beb
Compare
There was a problem hiding this comment.
Pull request overview
Friend, this PR updates the Apps build plugin’s backend virtual-entry code generation to initialize the @datadog/apps backend runtime context ($) inside generated backend function bundles, aligning the generated entries with how the SDK expects helpers to run.
Changes:
- Add conditional detection of
@datadog/apps/backend/internal(via Node module resolution) and generate an optional import forsetBackendContext. - Emit a generated snippet to call
setBackendContext($)afterglobalThis.$ = $and before action-catalog registration / handler execution. - Extend unit tests to cover presence/absence of the backend-internal import and validate call ordering.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/plugins/apps/src/backend/virtual-entry.ts | Adds conditional SDK import and injects backend-context initialization into generated main($) entry. |
| packages/plugins/apps/src/backend/virtual-entry.test.ts | Adds coverage for the new conditional import and ordering constraints. |
| packages/plugins/apps/src/backend/shared.ts | Introduces reusable “is export installed” resolver + new import/snippet constants for Apps backend context. |
| packages/plugins/apps/src/backend/shared.test.ts | Adds unit tests for the new backend-context snippet behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why?
Backend functions using
@datadog/appsneed the runtime$context before SDK helpers run. Generated backend entries already receive that context, so the build plugin should initialize the SDK rather than requiring customer-authored handlers to wire it manually.This follows the existing action-catalog integration pattern while keeping the import optional for projects that do not expose the new SDK backend-internal entry point.
How?
@datadog/apps/backend/internalfrom the customer project using Node module resolution.setBackendContextinto generated backend entries.setBackendContext($)after the runtime global is assigned and before action-catalog registration or the customer handler.The paired SDK change emits
@datadog/apps/backend/internaland public backend modules against one shared code-split module, so this setter updates the same context read by SDK helpers.Related SDK work
QA
A staging URL is not applicable because this only changes build-time generation for backend function bundles.
yarn formatyarn --cwd packages/plugins/apps run typecheckyarn typecheck:allyarn test:unit packages/plugins/apps/src/backend/shared.test.ts packages/plugins/apps/src/backend/virtual-entry.test.ts --runInBand— 31 passing testsyarn cli integrityBlast radius
Limited to generated Datadog Apps backend entries when the customer project exposes
@datadog/apps/backend/internal. Existing action-catalog initialization and projects without that SDK entry point retain their current behavior.